<template>
    <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from '../../dashboard/mixins/resize'

const animationDuration = 6000

export default {
    mixins: [resize],
    props: {
        className: {
            type: String,
            default: 'chart'
        },
        width: {
            type: String,
            default: '100%'
        },
        height: {
            type: String,
            default: '200px'
        }
    },
    data() {
        return {
            chart: null
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.initChart()
        })
    },
    beforeDestroy() {
        if (!this.chart) {
            return
        }
        this.chart.dispose()
        this.chart = null
    },
    methods: {
        initChart() {
            this.chart = echarts.init(this.$el, 'macarons')
            let option = {
                color: ["#617899", "#5397ff", "#0fdda8"],
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    show: false,
                    bottom: "10%",
                    icon: "circle",
                },
                title: [
                    {
                        text: "用电量",
                        left: "0",
                        top: "0",
                        textStyle: {
                            fontSize: 18,
                            fontWeight: "bold",
                            color: "#333",
                        },
                    },
                    {
                        text: "总",
                        textStyle: {
                            color: "rgba(28, 31, 35, 0.80)",
                            fontSize: "12px",
                            fontWeight: "normal",
                        },
                        subtext: 275,
                        subtextStyle: {
                            color: "#1C1F23",
                            fontSize: "20px",
                            fontWeight: "600",
                        },
                        top: "40%",
                        left: "center",
                    },
                ],
                series: [
                    {
                        name: "用电量",
                        type: "pie",
                        radius: ["40%", "65%"],
                        avoidLabelOverlap: false,
                        label: {
                            show: false,
                        },
                        labelLine: {
                            show: false,
                            lineStyle: {
                                cap: "round",
                            },
                        },
                        data: [
                            { value: 1048, name: "异步审核" },
                            { value: 735, name: "客服" },
                            { value: 580, name: "在线客服" },
                        ],
                    },
                ],
            };
            this.chart.setOption(option)
        }
    }
}
</script>
